package de.szut.ita13sommerfeld.blockadventure.gameentities.blocks.missiles;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.LinkedList;

import de.szut.ita13sommerfeld.blockadventure.controller.Controller;
import de.szut.ita13sommerfeld.blockadventure.gameentities.Entity;
import de.szut.ita13sommerfeld.blockadventure.gameentities.Missile;
import de.szut.ita13sommerfeld.blockadventure.gameentities.types.MissileType;
import de.szut.ita13sommerfeld.blockadventure.level.SpawnPoint;

public class AIM120 extends Missile {
	
	private BufferedImage[] tex = new BufferedImage[2];
	private float speed;
	private final float MAX_VELOCITY = 7.5f;
	
	public AIM120(float x, float y, float width, float height, SpawnPoint spawnpoint,
			float speed, int damage, int dir) {
		super(x, y, width, height, spawnpoint, damage, dir);
		this.speed = speed;
		tex[0] = texture.getMissileTexture(MissileType.MissileLeft);
		tex[1] = texture.getMissileTexture(MissileType.MissileRight);
	}

	public void render(Graphics g) {
		g.setColor(Color.BLUE);
		g.fillRect((int)x, (int)y, (int)Missile.WIDTH, (int)Missile.HEIGHT);
	}

	public void tick(LinkedList<Entity> entities) {
		velocityX += speed;
		if(velocityX > MAX_VELOCITY)
			velocityX = MAX_VELOCITY;
		if(dir == Missile.DIR_LEFT) {
			x -= velocityX;
		} else if(dir == Missile.DIR_RIGHT) {
			x += velocityX;
		}
		if(x < 0 || x > camera.getViewArea().getMaximumX() || x < camera.getViewArea().getMinimumX()) {
			controller.addEntityToList(Controller.EntityList.REMOVE, this);
		}
		controller.checkCollision(this, entities);
	}

	public Rectangle getBounds() {
		return new Rectangle((int)x, (int)y, (int)width, (int)height);
	}
	
	public Rectangle getBottomBounds() {
		return new Rectangle((int)x + 5, (int)y + (int)(height - 5), (int)width - 10, (int)5);
	}

	public Rectangle getBoundsTop() {
		return new Rectangle((int)x + 5, (int)y, (int)width - 10, (int)5);
	}

	public Rectangle getBoundsRight() {
		return new Rectangle((int)(x + width - 5), (int)y + 5, (int)5, (int)height - 10);
	}

	public Rectangle getBoundsLeft() {
		return new Rectangle((int)x, (int)y + 5, (int)5, (int)height - 10);
	}
}
